﻿using System.Collections.Generic;
using ExcelMapper.Map;
using System;

namespace ExcelMapper
{
   public partial class ExcelDocument
    {             
            
       public List<IDictionary<string, object>> Load()
       {
           var mapper = new ExcelMap(this.PathFile, this.RowHeader, this.PreRowHeader, this.SheetPage);
           this.DocumentValues = mapper.LoadExcel();
           return this.DocumentValues;
       }

       public List<IDictionary<string, object>> GetDocumentValues()
       {
             if(this.DocumentValues == null)
             {
                 return Load();
             }
             else
             {
                 return this.DocumentValues;
             }
       }

       public List<string> GetHeaders()
       {
           if(DocumentValues != null)
           {
              if(DocumentValues.Count > 0)
              {
                return new List<string>(DocumentValues[0].Keys);
              }
           }
           throw new Exception("No values into DocumentValues, please execute Load() Method");
       }

       public void SetKeys(string primaryKeyColumnName, string secondaryKeyColunmName)
       {
           this.PrimaryKeyColumnName = primaryKeyColumnName;
           this.SecondaryKeyColumnName = secondaryKeyColunmName;
       }

    }
}
